package com.hongruan.action.Common;

import java.util.Enumeration;

import org.apache.log4j.Logger;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.hongruan.action.BaseAction;
import com.hongruan.common.ParamsMap;
import com.hongruan.utils.HttpUtils;

/**
 * 通用功能
 * 
 * @author ZhangWenLong
 * 
 */
@Controller("CommonAction")
@Scope("prototype")
public class CommonAction extends BaseAction {
	
	private static final long serialVersionUID = 8617271765045187736L;

	private static Logger logger = Logger.getLogger(CommonAction.class);
	
    @SuppressWarnings("rawtypes")
	public String sendHttp() {
        logger.info("sendHttp() begin...");
        
        String xmlResult = null;
        ParamsMap<String, String> params = new ParamsMap<String, String>();
        String key = "";
        String url = "";
        
        Enumeration enu = this.getRequest().getParameterNames();
        while (enu.hasMoreElements()) {
            key = (String) enu.nextElement();
            if ("url".equals(key)) {
                url = this.getRequest().getParameter(key);
            }else {
                params.add(key, this.getRequest().getParameter(key));
            }
        }
        
        try {
        	xmlResult = new HttpUtils().get(url, params);
        } catch (Exception e) {
            e.printStackTrace();
            logger.info("sendHttp() error " + e.getMessage());
        }
        
        this.writeAjaxResult(xmlResult);
        
        return null;
    }
	
}
